class Solution {
public:
    int minMoney(vector<int>& arr, int aim) {
        const int inf = 0x3f3f3f3f;
        vector<int> dp(aim+1, inf);
        dp[0] = 0;
        for (int x: arr) {
            for (int i = 1; i <= aim; ++i) {
                if (x <= i) {
                    dp[i] = min(dp[i], dp[i-x] + 1);
                }
            }
        }
        return dp[aim] != inf ? dp[aim] : -1;
    }
};